//
//  SEGQRCodeInviteView.m
//  ExcellentHome
//
//  Created by 揭婧雯 on 2017/2/27.
//  Copyright © 2017年 陈区. All rights reserved.
//

#import "SEGQRCodeInviteView.h"

@implementation SEGQRCodeInviteView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self customUI];
    }
    return self;
}

#pragma mark - 初始化界面

- (void)customUI
{
    self.backgroundColor =kColor_bg3;
    
    //白色背景视图
    self.contentView = [[UIView alloc] init];
    self.contentView.backgroundColor = kColor_W;
    self.contentView.layer.masksToBounds = YES;
    self.contentView.layer.cornerRadius = 5;
    [self addSubview:self.contentView];
    [self.contentView mas_makeConstraints:^(MASConstraintMaker* make) {
        make.centerX.equalTo(self.mas_centerX);
        make.centerY.equalTo(self.mas_centerY);
        make.width.mas_equalTo(270);
        make.height.mas_equalTo(299);
    }];
    
    //关闭按钮
    self.closeButton = [[UIButton alloc] init];
    self.closeButton.backgroundColor = [UIColor clearColor];
    [self.closeButton setImage:[UIImage imageWithContentsOfFile:SEGPicName(@"btn_dialog_close_gray")] forState:UIControlStateNormal];
    [self.closeButton addTarget:self action:@selector(closeButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.closeButton];
    [self.closeButton mas_makeConstraints:^(MASConstraintMaker* make) {
        make.top.equalTo(self.contentView.mas_top);
        make.right.equalTo(self.contentView.mas_right);
        make.width.mas_equalTo(35);
        make.height.mas_equalTo(35);
    }];
    
    //图片
    self.iconView = [[UIImageView alloc] init];
//    self.iconView.backgroundColor = [UIColor redColor];
    [self.contentView addSubview:self.iconView];
    [self.iconView mas_makeConstraints:^(MASConstraintMaker* make) {
        make.centerX.equalTo(self.contentView.mas_centerX);
        make.top.equalTo(self.contentView.mas_top).with.offset(40);
        make.width.mas_equalTo(190);
        make.height.mas_equalTo(190);
    }];
    
    //商品名称
    self.nameLabel = [[UILabel alloc] init];
    self.nameLabel.text = [NSString stringWithFormat:@"扫一扫二维码，加入%@",kAppName];
    self.nameLabel.font = [UIFont systemFontOfSize:13];
    self.nameLabel.textColor = kColor_2;
    self.nameLabel.numberOfLines = 2;
    self.nameLabel.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.nameLabel];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker* make) {
        make.centerX.equalTo(self.contentView.mas_centerX);
        make.bottom.equalTo(self.contentView.mas_bottom).with.offset(-40);
    }];
}

- (void)closeButtonClick:(UIButton*)sender
{
    self.hidden = YES;
//    [self removeFromSuperview];
}

- (void)createQRCodeWithUrl:(NSString*)url
{
    NSString *string = [NSString stringWithFormat:@"%@&channel=50",url];
    self.iconView.image = [string createQRForSize:190];;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
